import ajax from './ajax'

export default {
  loadEventPlayers(eventId, onSuccess) {
    ajax.get('/anon/douban/events/' + eventId + '/players')
        .then(onSuccess);
  },

  loadEvent(eventId, onSuccess) {
    ajax.get('/anon/douban/events/' + eventId)
        .then(onSuccess);
  },

  checkPlayer(eventId, user, onSuccess) {
    ajax.post('/anon/douban/events/'+eventId+'/check', {
          "id" : user.id,
          "checked": 1
    })
    .then(onSuccess)
    .catch(err=>{console.log(err)});
  },

  blackPlayer(eventId, user, cause, blockDays, onSuccess) {
    ajax.post('/anon/douban/events/'+eventId+'/check', {
      "id" : user.id,
      "checked": -1,
      "blockDays":blockDays,
      "tag":cause
    })
    .then(onSuccess)
    .catch(err=>{console.log(err)});
  },

  restorePlayer(eventId, user, onSuccess) {
    ajax.post('/anon/douban/events/'+eventId+'/check', {
      "id" : user.id,
      "checked": 0
    })
    .then(onSuccess)
    .catch(err=>{console.log(err)});
  },

  loadUserEventSeat(eventId, user, onSuccess) {
    ajax.get('/anon/douban/events/' + eventId + '/seat?userId=' + user.id)
        .then(onSuccess);
  },

  selectUserEventSeat(eventId, user, seatName, onSuccess, onError) {
    ajax.post('/anon/douban/events/' + eventId + '/seat', {
      "id" : user.id,
      "seat": seatName
    })
    .then(onSuccess)
    .catch(onError);
  }
};